{% extends "course/nav.html" %}
{% block title %}HomePage{% endblock %}
{% block content %}
    {% load static %}
    <link href="{% static 'css/list.css' %}" rel="stylesheet">
    <div class="main-container">
        <div class="main-bar">
            <form class="search-form" method="post">
                {% csrf_token %}
                <input class="input" id="search-key" type="text" name="search" {% if search_key != None %}value="{{ search_key }}" {% endif %}/>
                <input class="button" type="submit" value="搜索课程" />
            </form>

            {% if view_kind != "select"%}
                <input class="button right-button" type="button" value="选课"  onclick='window.open("{% url 'view_course' 'select' %}")' />
            {% endif %}
            {% if view_kind != "withdraw"%}
                <input class="button right-button" type="button" value="撤课"  onclick='window.open("{% url 'view_course' 'withdraw' %}")' />
            {% endif %}
            {% if view_kind != "is_end"%}
                <input class="button right-button" type="button" value="查看结课课程"  onclick='window.open("{% url 'view_course' 'is_end' %}")' />
            {% endif %}
            {% if view_kind != "current"%}
                <input class="button right-button" type="button" value="查看当前课程"  onclick='window.open("{% url 'view_course' 'current' %}")' />
            {% endif %}
        </div>
        <h3>{% if view_kind == "select"%}
                选课
            {% elif view_kind == "withdraw"%}
                撤课
            {% elif  view_kind == "is_end"%}
                查看结课课程
            {% elif view_kind == "current"%}
                查看当前课程
            {% endif %}</h3>
        <table class="item-list course-list">
            <thead>
                <tr>
                    <th class="course-no">课程编号</th>
                    <th class="course-name">名称</th>
                    <th class="course-credit">学分</th>
                    {% if view_kind == "is_end" %}
                        <th class="course-year-semester">年份学期</th>
                    {% else %}
                        <th class="course-number">当前人数/<br>最大人数</th>
                        <th class="course-year">年份</th>
                        <th class="course-semester">学期</th>
                    {% endif %}
                    <th class="course-teacher">教师</th>
                    {% if view_kind == "is_end" %}
                        <th class="course-scores">得分</th>
                        <th class="course-comments">评语</th>
                        <th class="course-rating">学生评分</th>
                        <th class="course-assessment">学生评价</th>
                        <th class="course-operation student-course">操作</th>
                    {% else %}
                        <th class="course-schedule">上课时间</th>
                        <th class="course-operation student-course">操作</th>
                    {% endif %}
                </tr>
            </thead>
            <tbody>
            {% if view_kind == "is_end" %}
                {# end course show student course #}
                {% for sc in course_list %}
                <tr id="course-id-{{ sc.course.id }}">
                    <td class="course-no">{{ sc.course.id }}</td>
                    <td class="course-name">{{ sc.course.name }}</td>
                    <td class="course-credit">{{ sc.course.credit }}</td>
                    <td class="course-year-semester">{{ sc.course.year }} {{ sc.course.get_semester_display }}</td>
                    <td class="course-teacher">{{ sc.course.teacher.name }}</td>
                    <td class="course-scores">{{ sc.scores }}</td>
                    <td class="course-comments">{{ sc.comments }}</td>
                    {% if sc.rating == None %}
                        <td class="course-rating">-</td>
                        <td class="course-assessment">-</td>
                        <td class="course-operation student-course">
                        <input class="button" type="button" value="查看详情" onclick='location.href="{% url 'sview_detail' sc.id%}"' />
                        <input class="button" type="button" value="评教"
                               onclick='window.open("{% url 'evaluate' sc.id %}")' />
                        </td>
                    {% else %}
                        <td class="course-rating">{{ sc.rating }}</td>
                        <td class="course-assessment">{{ sc.assessment }}</td>
                        <td class="course-operation student-course">
                        <input class="button" type="button" value="查看详情" onclick='location.href="{% url 'sview_detail' sc.id%}"' />
                        </td>
                    {% endif %}
                </tr>
                {% endfor %}
            {% else %}
                {% for course in course_list %}
                <tr id="course-id-{{ course.id }}">
                    <td class="course-no">{{ course.id }}</td>
                    <td class="course-name">{{ course.name }}</td>
                    <td class="course-credit">{{ course.credit }}</td>
                    <td class="course-number">{{ course.get_current_count }}/{{ course.max_number }}</td>
                    <td class="course-year">{{ course.year }}</td>
                    <td class="course-semester">{{ course.get_semester_display }}</td>
                    <td class="course-teacher">{{ course.teacher.name }}</td>
                    <td class="course-schedule">
                        {% for schedule in course.get_schedules %}
                            <div>{{ schedule }}</div>
                        {% endfor %}
                    </td>
                        <td class="course-operation student-course">
                        {% if view_kind == "select"%}
                            <input class="button" type="button" value="选课"
                                   onclick='window.open("{% url 'operate_course' course.id 'select' %}")' />
                        {% endif %}
                        {% if view_kind == "withdraw"%}
                            <input class="button" type="button" value="撤课"
                                   onclick='window.open("{% url 'operate_course' course.id 'withdraw' %}")' />
                        {% endif %}
                        {% if view_kind == "current"%}
                            -
                        {% endif %}
                        </td>
                </tr>
                {% endfor %}
            {% endif %}
            </tbody>

        </table>
    </div>
{% endblock %}